<template>
  <div class="header">
    <div class="logo">
      <div class="icon"></div>
      <span class="logo_text">{{ project.Chinese }}</span>
    </div>
  </div>
  <div class="main">
    <div class="content">
      <div class="newclub_box">
        <a target="_blank" href="#">
          <img src="https://pic5.40017.cn/i/ori/1h2lPMqyhEY.jpg" title="" alt="同程PC登录页左侧默认广告">
        </a>
      </div>
      <div class="login_box">
          <div class="login_con ">
            <div class="login_tab" v-loading="loginLoading" element-loading-text="loading">
              <ul class="clearfix" style="display: flex;justify-content: space-between">
                <li class="login_tab_common" v-bind:class="{at : login}" @click="login=true;res=false">登&nbsp;&nbsp;&nbsp;录</li>
                <li class="login_tab_phone" v-bind:class="{at : res}" @click="login=false;res=true">注&nbsp;&nbsp;&nbsp;册</li>
              </ul>
              <div class="body_card">
                <div class="protocol_tips">
                  <span>登录即代表您已阅读并同意</span>
                  <a href="https://www.ly.com/public/Lawprotocols" target="view_window">《服务协议及隐私政策》</a>
                </div>
                <div class="quick_icon">
                  <a></a>
                  <a class="qq"></a>
                  <a class="zfb"></a>
                  <a class="wb"></a>
                </div>
                <div v-if="login" class="main_body">
                  <form>
                    <input type="text"
                           maxlength="20"
                           class="input"
                           :placeholder="tagName"
                           @focusin="tagName = ''"
                           @focusout="tagName = '输入用户名'"
                           v-model="userLogin.name"
                           required>
                    <input type="password"
                           maxlength="20"
                           class="input"
                           :placeholder="tag"
                           @focusin="tag = ''"
                           @focusout="tag = '输入密码'"
                           v-model="userLogin.password"
                           required>
                    <el-button class="login_btn" native-type="submit" @click.stop="loginBtn">
                      登录
                    </el-button>
                  </form>

                </div>
                <div v-if="res" class="main_body res">
                  <input type="text"
                         maxlength="20"
                         class="input"
                         :placeholder="tagName"
                         @focusin="tagName = ''"
                         @focusout="tagName = '输入用户名'"
                         v-model="userRegister.name"
                         required>
                  <input type="password"
                         maxlength="20"
                         class="input"
                         :placeholder="tag"
                         @focusin="tag = ''"
                         @focusout="tag = '输入密码'"
                         v-model="userRegister.password"
                         required>
                  <input type="text"
                         maxlength="20"
                         class="input"
                         :placeholder="tagEmail"
                         @focusin="tagEmail = ''"
                         @focusout="tagEmail = '输入邮箱'"
                         v-model="userRegister.email"
                         required>
                  <el-button class="login_btn" >
                    注册
                  </el-button>
                </div>
              </div>

            </div>

        </div>
      </div>
    </div>
  </div>

</template>

<script setup>
import {useStore} from "vuex";
import {ref,reactive} from "vue";
import {useRouter} from "vue-router";
import qs from "qs";
import axios from "axios";
import { ElMessage } from 'element-plus'
import constant from "../../constant";

const router = useRouter()
const store = useStore()
const project = store.state.projectLogo

let login = ref(true)
let res = ref(false)
let tag = ref("输入密码")
let tagName = ref("输入用户名")
let tagEmail = ref("输入邮箱")
let loginLoading = ref(false)

let userLogin = reactive({
  name : '',
  password : ''
})
let userRegister = reactive(store.state.user)

// 点击登录
function loginBtn() {
  if ( userLogin.name !== '' || userLogin.password !== '') {
    axios.post("/api/login", qs.stringify(userLogin))
        .then((res) => {
          if (res.status === constant.ResponseCode.INCONSISTENT_PAR) {
            ElMessage.warning('密码错误')
          } else if (res.status === constant.ResponseCode.SELECTED_NOTFOUND) {
            ElMessage.warning('用户未注册')
          } else if (res.status === constant.ResponseCode.SUCCESS){
            store.state.user = {...res.data}
            loginLoading = true
            if (store.state.user.uid !== 0) {
              loginLoading = false
              ElMessage.success('登录成功')
              router.replace("/")
            } else {
              ElMessage.error("error")
            }

          } else {
            ElMessage.error('未响应')
          }
        })
        .catch((exception) => {
          console.log(exception)
          ElMessage.error(exception)
        })
  }

}


</script>

<style scoped>
.header {
  width: 1190px;
  margin: 0 auto;
  padding: 5px 0;
  position: relative;
}
.logo {
  height: 80px;
  display: flex;
  align-items: center;

}
.icon {
  position: relative;
  width: 56px;
  height: 56px;
  /*background: red;*/
  background: url(../../assets/logo.svg) no-repeat;
  display: inline-block;
  margin-left: 2px;
  background-size: contain !important;
  background-position: 50% !important;
}
.logo_text {
  font-size: 28px;
  margin-left: 10px;
  color: #13227a;
  /*font-family: "alimama",fantasy;*/
  font-family: "仓耳渔阳体 W04", fantasy;
  font-weight: 400;
}
.main {
  height: 494px;
  overflow: hidden;
  width: 100%;
  position: relative;
}
.content {
  width: 1190px;
  margin: 0 auto;
  position: relative;
}
img {
  width: 1920px;
  height: 494px;
  display: block;
}
.newclub_box {
  margin-left: -960px;
  left: 50%;
  position: relative;
  height: 494px;
}
.login_box {
  width: 350px;
  height: 435px;
  background: #fff;
  position: absolute;
  top: 30px;
  right: 0;
  box-shadow: 0 1px 12px 11px rgb(137 47 47 / 12%);
}
.login_tab {
  height: 43px;
  padding-top: 23px;
  /*border-bottom: 1px solid #e4e4e4;*/
}
.login_con {
  width: 270px;
  margin: 0 auto;
}
ul {
  list-style-type: disc;
  margin-block-start: 1em;
  margin-block-end: 1em;
  margin-inline-start: 0;
  margin-inline-end: 0;
  padding: 0;
}
li {
  list-style: none;
}
.login_tab ul li.at {
  color: #00c777;
  font-weight: 700;
  border-bottom: 2px solid #00c777;
}
.login_tab ul li {
  line-height: 42px;
  color: #333;
  font-size: 16px;
  float: left;
  cursor: pointer;
  margin: 0;
}
.clearfix:after {
  content: '.';
  display: block;
  clear: both;
  line-height: 0;
  height: 0;
  visibility: hidden;
}
.login_tab ul {
  border-bottom: 1px solid #e4e4e4;
}
.body_card {
  display: flex;
  /*align-items: center;*/
  flex-direction: column-reverse;
  height: 300px;
}
.main_body{
  display: flex;
  align-items: center;
  flex-direction: column;
  padding: 30px 0;
  height: 270px;
}
.input{
  list-style: none;
  margin: 10px 0 10px 0;
  font-family: 'Microsoft YaHei',Arial,sans-serif;
  width: 270px;
  padding: 0 10px;
  height: 36px;
  line-height: 36px;
  outline: 0;
  border: 1px solid #ddd;
  border-radius: 2px;
  font-size: 14px;
  color: #ccc;
}
.input:focus {
  color: #333;
}
.input::-webkit-input-placeholder {
  font-size: 14px;
  color: #ccc;
}
.login_btn {
  width: 270px;
  height: 44px;
  /*line-height: 44px;*/
  color: #fff;
  font-size: 20px;
  background: #ff6257;
  text-align: center;
  display: block;
  border-radius: 3px;
  margin-top: 20px;
}
.quick_icon {
  height: 50px;
  width: 270px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 5px 10px 5px;
}
.protocol_tips {
  font-size: 12px;
  color: #999;
  position: absolute;
  bottom: 20px;
}
.protocol_tips a {
  text-decoration: none;
  cursor: pointer;
  color: #999;
}
.quick_icon a {
  width: 35px;
  height: 35px;
  display: inline-block;
  float: right;
  background: url(//pic5.40017.cn/02/000/39/c9/rBANDFo8bGCAHhAFAAAc0juH33Q996.png) no-repeat 0 0;
}
a {
  text-decoration: none;
}
.quick_icon a.qq {
  background-position: 0 -48px;
}
.quick_icon a.zfb{
  background-position: 0 -100px;
}
.quick_icon a.wb{
  background-position: 0 -152px;
}
.quick_icon a:hover{
  background-position: -52px 0;
}
.quick_icon a.qq:hover {
  background-position: -52px -48px;
}
.quick_icon a.zfb:hover{
  background-position: -52px -100px;
}
.quick_icon a.wb:hover{
  background-position: -52px -152px
}
.main_body_res {
  padding-top: 0;
}
.login_tab_common {
  width: 50%;
}
.login_tab_phone{
  width: 50%;
}
</style>